﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;
using System.IO;

public partial class UserPlanWeek_EvaluateUserPlanWeek : System.Web.UI.Page
{
    WeekDateManager dllWeekDateManager = new WeekDateManager();
    IBussinessLogic dllUserInfo = new UserInfoManager();
    Authentication dllAuthentication = new Authentication();
    VerifyCircuitManager dllVerifyCircuitManager = new VerifyCircuitManager();
    UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
    MonthDateManager dllMonthDateManager = new MonthDateManager();
    QuarterDateManager dllQuarterDateManager = new QuarterDateManager();
    Model.UserInfo objUserInfo = new Model.UserInfo();
    DataTable _powerTable = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();

        if (!IsPostBack)
        {
            if (Request.Params["type"] != null && Request.Params["type"].ToString().Length != 0)
            {
                this.drpType.SelectedIndex = this.drpType.Items.IndexOf(this.drpType.Items.FindByValue(Request.Params["type"].ToString()));
            }
            bindDropDownList(this.drpYear);
            bindDropDownList(this.drpQuarterDate);
            if (this.drpType.SelectedItem.Value == "0")
            {
                //绑定待评估
                bindGridViewCheckNote();
                this.btnOk.Visible = false;
                this.btnReturn.Visible = false;
                this.ckbAllSelect.Visible = false;

            }
            else
            {
                //绑定是否达成共识
                bindGridView();
                this.btnOk.Visible = true;
                this.btnReturn.Visible = true;

                this.ckbAllSelect.Visible = true;
            }

        }
    }

    /// <summary>
    /// 绑定dropdownlist
    /// </summary>
    /// <param name="_drp"></param>
    void bindDropDownList(DropDownList _drp)
    {
        //年份绑定
        if (_drp.Equals(this.drpYear))
        {
            for (int i = 2009; i < 2100; i++)
            {
                ListItem _li = new ListItem(i.ToString(), i.ToString());
                _drp.Items.Add(_li);
            }
            //根据系统日期自动绑定到当前年份
            //string _year = DateTime.Now.Year.ToString();
            //this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year));
            //根据系统当前日期查找到对应的年周期
            DataTable _year = dllQuarterDateManager.getQuarterDate();
            this.drpYear.SelectedIndex = this.drpYear.Items.IndexOf(this.drpYear.Items.FindByText(_year.Rows[0][2].ToString()));

        }

        //绑定年计划周期
        if (_drp.Equals(this.drpQuarterDate))
        {
            object[] _value = new object[1];
            _value[0] = this.drpYear.SelectedValue;
            DataTable _quarter = dllQuarterDateManager.get(QuarterDateManager.field.QuarterYear.ToString(), _value);
            if (_quarter.Rows.Count != 0)
            {
                this.drpQuarterDate.DataSource = _quarter;
                this.drpQuarterDate.DataTextField = "QuarterName";
                this.drpQuarterDate.DataValueField = "Quarter_Id";
                this.drpQuarterDate.DataBind();
                #region dropdownlist显示系统所对应的当前年周期
                //根据系统当前日期查找到对应的年周期
                DataTable _quartertime = dllQuarterDateManager.getQuarterDate();
                //如果查到结果（结果只有一条）

                if (_quartertime.Rows.Count == 1)
                {
                    this.drpQuarterDate.SelectedIndex = this.drpQuarterDate.Items.IndexOf(this.drpQuarterDate.Items.FindByText(_quartertime.Rows[0][1].ToString()));
                }
                #endregion
                bindDropDownList(this.drpMonthDate);
            }
            else
            {
                ListItem _li = new ListItem("无年周期");
                this.drpQuarterDate.Items.Clear();
                this.drpQuarterDate.Items.Add(_li);
                bindDropDownList(this.drpMonthDate);
            }
        }
        //绑定月计划周期
        if (_drp.Equals(this.drpMonthDate))
        {
            object[] _value = new object[2];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            DataTable _month = dllMonthDateManager.get(MonthDateManager.field.QuarterName.ToString(), _value);
            if (_month.Rows.Count != 0)
            {
                this.drpMonthDate.DataSource = _month;
                this.drpMonthDate.DataTextField = "MonthName";
                this.drpMonthDate.DataValueField = "Month_Id";
                this.drpMonthDate.DataBind();
                #region 根据系统当前日期绑定到当前月周期
                DataTable _monthtime = dllMonthDateManager.getMonthDate();
                if (_monthtime.Rows.Count == 1)
                {
                    this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByText(_monthtime.Rows[0][3].ToString()));
                }
                #endregion

                bindDropDownList(this.drpWeekDate);
                if (Request.QueryString["PreWeekDate"] != null)
                {
                    object[] _date = new object[1];
                    int PreWeekDate = 0;
                    _date[0] = Convert.ToInt32(this.drpWeekDate.SelectedValue);
                    _date[0] = PreWeekDate = dllWeekDateManager.getPreWeekDate(_date);
                    DataTable dt_Monthdate = dllWeekDateManager.get(BLL.WeekDateManager.field.Week_Id.ToString(), _date);
                    if (dt_Monthdate.Rows.Count > 0)
                    {
                        this.drpMonthDate.SelectedIndex = this.drpMonthDate.Items.IndexOf(this.drpMonthDate.Items.FindByText(dt_Monthdate.Rows[0]["MonthName"].ToString()));
                        bindDropDownList(this.drpWeekDate);
                        this.drpWeekDate.SelectedValue = PreWeekDate.ToString();

                    }

                }
            }
            else
            {
                ListItem _li = new ListItem("无月周期");
                this.drpMonthDate.Items.Clear();
                this.drpMonthDate.Items.Add(_li);
                bindDropDownList(this.drpWeekDate);
            }

        }
        //绑定周计划周期
        if (_drp.Equals(this.drpWeekDate))
        {
            object[] _value = new object[3];
            _value[0] = this.drpYear.SelectedValue;
            _value[1] = this.drpQuarterDate.SelectedItem.Text;
            _value[2] = this.drpMonthDate.SelectedItem.Text;
            DataTable _week = dllWeekDateManager.get(WeekDateManager.field.MonthName.ToString(), _value);
            if (_week.Rows.Count != 0)
            {
                this.drpWeekDate.DataSource = _week;
                this.drpWeekDate.DataTextField = "WeekName";
                this.drpWeekDate.DataValueField = "Week_Id";
                this.drpWeekDate.DataBind();
                DataTable _weektime = dllWeekDateManager.getWeekDate();
                if (_weektime.Rows.Count == 1)
                {
                    this.drpWeekDate.SelectedIndex = this.drpWeekDate.Items.IndexOf(this.drpWeekDate.Items.FindByText(_weektime.Rows[0][4].ToString()));
                    if (Request.Params["Id"] != null && Request.Params["Id"].ToString().Length != 0)
                    {

                        this.drpWeekDate.SelectedIndex = this.drpWeekDate.Items.IndexOf(this.drpWeekDate.Items.FindByValue(Request.Params["Id"].ToString()));

                    }

                }
                ListItem _li = this.drpType.SelectedItem;
                if (_li != null)
                {
                    if (_li.Text == "待审核")
                    {
                        bindGridView();
                    }
                    else
                    {
                        bindGridViewCheckNote();
                    }
                }
            }
            else
            {
                ListItem _li = new ListItem("无周周期");
                this.drpWeekDate.Items.Clear();
                this.drpWeekDate.Items.Add(_li);
            }
        }
    }



    /// <summary>
    /// 根据逗号换行事件
    /// </summary>
    void wrapByComma(GridView _gridView, int _rowIndex, int _cells)
    {
        string _content = _gridView.Rows[_rowIndex].Cells[_cells].Text;
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&lt;br&gt;", "<br>");
        //_gridView.Rows[_rowIndex].Cells[_cells].Text = _content.Replace("&gt;", ">");
        _gridView.Rows[_rowIndex].Cells[_cells].Text = _gridView.Rows[_rowIndex].Cells[_cells].Text.Replace(",", "<br>");


    }



    /// <summary>
    /// 绑定是否达成共识GridView（处理待评估、待审核计划）
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-2-25</date>
    void bindGridView()
    {
        //根据评估人查询当前用户的待审待评估计划
        object[] _value = new object[2];
        Model.UserInfo objUserInfo = new Model.UserInfo();
        _value[0] = objUserInfo.UserName;
        ListItem _li = this.drpWeekDate.SelectedItem;
        if (_li != null)
        {
            _value[1] = Convert.ToInt32(_li.Value);
            DataView dv = new DataView(dllUserPlanWeek.getUserWeekPlanNoEvaluateAndNoVerify(_value));
            dv.Sort = "WeekPlanSortId";
            this.gdvNoEvaluateWeekPlan.DataSource = dv;
            this.gdvNoEvaluateWeekPlan.DataBind();
            #region 截取字符串
            for (int i = 0; i < this.gdvNoEvaluateWeekPlan.Rows.Count; i++)
            {
                TextBox tb = (TextBox)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[13].FindControl("txtVerifyPeopleOpinion");
                tb.Text = this.gdvNoEvaluateWeekPlan.DataKeys[i]["VerifyPeopleOpinion"].ToString();
                if (Convert.ToInt32(this.gdvNoEvaluateWeekPlan.DataKeys[i]["PlanSendState"]) >= 2)
                {
                    tb.Enabled = false;
                }
                else
                {
                    tb.Enabled = true;
                }
                wrapByComma(this.gdvNoEvaluateWeekPlan, i, 7);
                wrapByComma(this.gdvNoEvaluateWeekPlan, i, 8);
                if (this.gdvNoEvaluateWeekPlan.Rows[i].Cells[11].Text == "&nbsp;" || this.gdvNoEvaluateWeekPlan.Rows[i].Cells[11].Text == "&amp;nbsp;")
                {
                    this.gdvNoEvaluateWeekPlan.Rows[i].Cells[11].Text = "";
                }

                if (this.gdvNoEvaluateWeekPlan.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                {
                    Button _btn = (Button)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[12].FindControl("btnDownLoad");
                    _btn.Visible = false;
                    Label _lbl = (Label)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[12].FindControl("lblAlert");
                    _lbl.Visible = true;
                    _lbl.Text = "无下载";
                }
            }
            #endregion


            #region
            for (int i = 0; i < gdvNoEvaluateWeekPlan.Rows.Count; i++)
            {
                LinkButton lbtn = (LinkButton)gdvNoEvaluateWeekPlan.Rows[i].Cells[4].FindControl("lbtnSource");
                lbtn.Text = gdvNoEvaluateWeekPlan.DataKeys[i]["Source"].ToString();
                //文件下载，判断如果下载了就显示《下载按钮》 反之 就显示“无下载”
                if (gdvNoEvaluateWeekPlan.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                {
                    Button _btn = (Button)gdvNoEvaluateWeekPlan.Rows[i].Cells[13].FindControl("btnDownLoad");
                    _btn.Visible = false;
                    Label _lbl = (Label)gdvNoEvaluateWeekPlan.Rows[i].Cells[13].FindControl("lblAlert");
                    _lbl.Visible = true;
                    _lbl.Text = "无下载";
                }
            }

            #endregion


        }
    }

    /// <summary>
    /// 自动分页事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gdvNoEvaluateWeekPlan_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.gdvNoEvaluateWeekPlan.PageIndex = e.NewPageIndex;
        bindGridView();
    }
    /// <summary>
    /// 通过按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnOk_Click(object sender, EventArgs e)
    {
        //根据评估人查询当前用户的待审周计划
        Model.UserInfo objUserInfo = new Model.UserInfo();
        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvNoEvaluateWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                object[] _value = new object[3];
                _value[0] = Convert.ToInt32(this.gdvNoEvaluateWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                _value[1] = objUserInfo.UserName;
                TextBox tb = (TextBox)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[12].FindControl("txtVerifyPeopleOpinion");
                if (tb.Text.Length < 18)
                {
                    Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
                    return;
                }
                _value[2] = tb.Text;
                _valueList.Add(_value);
                _count++;
            }
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请至少选择一个周计划", Page);
            return;
        }
        //修改发送状态为2，进入审核流程
        if (this.drpType.SelectedItem.Text != null && this.drpType.SelectedItem.Value == "1")
        {
            int result = dllUserPlanWeek.editWithTransaction(UserPlanWeek.field.EvaluatePeople.ToString(), _valueList);
            if (result == 0)
            {
                Utility.Error.RedirectErrorPage("提交周计划评估未成功，请重试！");
            }
            else
            {
                Response.Redirect("EvaluateUserPlanWeek.aspx");
            }
        }

    }
    /// <summary>
    /// 全选事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ckbAllSelect_CheckedChanged(object sender, EventArgs e)
    {
        if (ckbAllSelect.Checked == true)
        {
            for (int i = 0; i < this.gdvNoEvaluateWeekPlan.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
                ckb.Checked = true;
            }
        }
        else
        {
            for (int i = 0; i < this.gdvNoEvaluateWeekPlan.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
                ckb.Checked = false;
            }
        }
    }
    /// <summary>
    /// 退回按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnReturn_Click(object sender, EventArgs e)
    { //根据评估人查询当前用户的待审月计划
        Model.UserInfo objUserInfo = new Model.UserInfo();

        int _count = 0;
        List<object[]> _valueList = new List<object[]>();
        for (int i = 0; i < this.gdvNoEvaluateWeekPlan.Rows.Count; i++)
        {
            string a = this.gdvNoEvaluateWeekPlan.Rows[i].Cells[2].Text;
            CheckBox ckb = (CheckBox)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                object[] _value = new object[2];
                _value[0] = Convert.ToInt32(this.gdvNoEvaluateWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                TextBox tb = (TextBox)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[11].FindControl("txtVerifyPeopleOpinion");
                if (tb.Text.Length < 18)
                {
                    Utility.HttpHelp.alert("审核意见字数不得低于32个字符", Page);
                    return;
                }
                _value[1] = tb.Text;
                _valueList.Add(_value);
                _count++;
            }
        } if (_count == 0)
        {
            Utility.HttpHelp.alert("请至少选择一个月计划", Page);
            return;
        }
        //修改周计划发送状态为0，填写checknote字段内容（追加）

        int result = dllUserPlanWeek.editWithTransaction(UserPlanWeek.field.CheckNote.ToString(), _valueList);

        if (result == 0)
        {
            Utility.Error.RedirectErrorPage("退回周计划未成功，请重试！");
        }
        else
        {
            Response.Redirect("EvaluateUserPlanWeek.aspx");
        }
    }


    /// <summary>
    /// 计划类型选择项改变
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.drpType.SelectedItem.Value == "0")
        {
            //绑定待评估
            bindGridViewCheckNote();
            this.gdvNoEvaluateWeekPlan.Visible = false;
            this.gdvEvaluteCheckNote.Visible = true;
            this.btnOk.Visible = false;
            this.btnReturn.Visible = false;
            this.ckbAllSelect.Visible = false;
        }
        else
        {
            //绑定是否达成共识            
            bindGridView();
            this.gdvNoEvaluateWeekPlan.Visible = true;
            this.gdvEvaluteCheckNote.Visible = false;
            this.btnOk.Visible = true;
            this.btnReturn.Visible = true;
            this.ckbAllSelect.Visible = true;
        }
    }
    /// <summary>
    /// 绑定待评估GridView
    /// </summary>
    void bindGridViewCheckNote()
    {
        //根据评估人查询当前用户的待最后一次评估的计划
        Model.UserInfo objUserInfo = new Model.UserInfo();
        object[] _value = new object[2];
        ListItem _li = this.drpWeekDate.SelectedItem;
        if (_li != null)
        {

            if (_li.Text != "无周周期")
            {
                _value[0] = objUserInfo.UserName;
                _value[1] = Convert.ToInt32(_li.Value);
                DataView dv = new DataView(dllUserPlanWeek.getUserWeekPlanEvaluatedAndVerified(_value));
                dv.Sort = "WeekPlanSortId";
                this.gdvEvaluteCheckNote.DataSource = dv;
                this.gdvEvaluteCheckNote.DataBind();


                #region 截取字符串
                for (int i = 0; i < this.gdvEvaluteCheckNote.Rows.Count; i++)
                {
                    if (this.gdvEvaluteCheckNote.Rows[i].Cells[10].Text == "&nbsp;" || this.gdvEvaluteCheckNote.Rows[i].Cells[10].Text == "&amp;nbsp;")
                    {
                        this.gdvEvaluteCheckNote.Rows[i].Cells[10].Text = "";
                    }
                    DropDownList drp = (DropDownList)this.gdvEvaluteCheckNote.Rows[i].Cells[11].FindControl("dropZhuangTai");
                    drp.SelectedValue = this.gdvEvaluteCheckNote.DataKeys[i]["PlanSendState"].ToString();
                    if (Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["PlanSendState"].ToString()) > 3)
                    {
                        Button btn = (Button)this.gdvEvaluteCheckNote.Rows[i].Cells[12].FindControl("btnTiJiao");
                        btn.Enabled = false;
                    }
                    else
                    {
                        drp.SelectedValue = "4";
                    }

                }
                #endregion

                #region
                for (int i = 0; i < gdvEvaluteCheckNote.Rows.Count; i++)
                {
                    //文件下载，判断如果下载了就显示《下载按钮》 反之 就显示“无下载”
                    if (gdvEvaluteCheckNote.DataKeys[i]["AttachmentPath"].ToString().Length == 0)
                    {
                        Button _btn = (Button)gdvEvaluteCheckNote.Rows[i].Cells[12].FindControl("btnDownLoad1");
                        _btn.Visible = false;
                        Label _lbl = (Label)gdvEvaluteCheckNote.Rows[i].Cells[12].FindControl("lblAlert1");
                        _lbl.Visible = true;
                        _lbl.Text = "无下载";
                    }
                }

                #endregion
            }
        }

    }
    /// <summary>
    /// 是否达成共识的提交按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnTiJiao_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button bt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        DropDownList drp = (DropDownList)this.gdvEvaluteCheckNote.Rows[i].Cells[11].FindControl("dropZhuangTai");
        ListItem _li = drp.SelectedItem;

        if (_li != null)
        {
            if (_li.Text != "请选择")
            {
                object[] _value = new object[3];
                _value[0] = Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["WeekPlanId"].ToString());
                TextBox tb = (TextBox)this.gdvEvaluteCheckNote.Rows[i].Cells[11].FindControl("txtCheckNote");
                if (tb.Text.Length < 18)
                {
                    Utility.HttpHelp.alert("评估意见不得少于32个字符", Page);
                    return;
                }
                tb.Text = tb.Text + "\r\n";
                _value[1] = tb.Text;
                _value[2] = Convert.ToInt32(((DropDownList)this.gdvEvaluteCheckNote.Rows[i].Cells[11].FindControl("dropZhuangTai")).SelectedItem.Value);
                //修改年计划发送状态为为传递过来的参数的发送状态，填写checknote字段内容（追加）
                int result = dllUserPlanWeek.edit(UserPlanWeek.field.CheckNote.ToString(), WeekPlanofManager.field.PlanSendState.ToString(), _value);
                if (result == 0)
                {
                    Utility.Error.RedirectErrorPage("提交评估意见未成功，请重试！");
                }
                else
                {
                    bindGridViewCheckNote();
                }
            }
            else
            {
                Utility.HttpHelp.alert("请选择计划完成状态", Page);
            }
        }
    }

    /// <summary>
    /// 查看流程
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnVerifyCircuit_Click(object sender, EventArgs e)
    {
        int _count = 0;
        string _url = "";
        int _quarterPlanId = 0;

        for (int i = 0; i < this.gdvEvaluteCheckNote.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvEvaluteCheckNote.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _count++;
                _quarterPlanId = Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["WeekPlanId"].ToString());
            }
        }

        for (int i = 0; i < this.gdvNoEvaluateWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _count++;
                _quarterPlanId = Convert.ToInt32(this.gdvNoEvaluateWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
            }
        }

        if (_count > 1)
        {
            Utility.HttpHelp.alert("只能选择一个计划", Page);
            return;
        }
        if (_count == 0)
        {
            Utility.HttpHelp.alert("请选择一个计划", Page);
            return;
        }
        if (_count == 1)
        {
            _url = "../WebCommon/VerifyCircruitForUserPlanDisplay.aspx?PlanId=" + _quarterPlanId + "&PlanType=5";
            Page.RegisterStartupScript("windowOpen",
               "<script language=javascript>window.open('" + _url + "','newwindow','height=150,width=550,top=250,left=300,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }

    }



    /// <summary>
    /// 年份改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpQuarterDate);
        bindDropDownList(this.drpMonthDate);
    }
    /// <summary>
    /// 年改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpQuarterDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpMonthDate);
    }

    /// <summary>
    /// 月改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpMonthDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        bindDropDownList(this.drpWeekDate);
    }

    /// <summary>
    /// 周改变事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void drpWeekDate_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListItem _li = this.drpType.SelectedItem;
        if (_li != null)
        {
            if (_li.Text == "待审核")
            {
                bindGridView();
            }
            else
            {
                bindGridViewCheckNote();
            }
        }
    }
    /// <summary>
    /// 附件下载
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnDownLoad_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvNoEvaluateWeekPlan.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
    }

    ///   <summary>   
    ///   文件下载   
    ///   </summary>   
    ///   <param   name="FullFileName"></param>   
    private void FileDownload(string strFileName)
    {
        FileInfo DownloadFile = new FileInfo(strFileName);
        if (!DownloadFile.Exists)
        {
            Utility.HttpHelp.alert("无附件,请与管理员联系", Page);
            return;
        }
        Response.Clear();
        Response.ClearHeaders();
        Response.Buffer = false;
        Response.ContentType = "application/octet-stream";
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(strFileName.Substring(strFileName.LastIndexOf('\\') + 1), System.Text.Encoding.UTF8));
        // Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());

        Response.WriteFile(DownloadFile.FullName);
        Response.Flush();
        Response.End();

    }

    protected void btnDownLoad1_Click(object sender, EventArgs e)
    {
        int i = 0;
        Button btt = (Button)sender;//获得当前控件
        TableCell cell = (TableCell)btt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行
        i = iRow.RowIndex;//得到该行的索引
        //读取隐藏地址列
        string path = this.gdvEvaluteCheckNote.DataKeys[i]["AttachmentPath"].ToString();
        FileDownload(path);
    }


    /// <summary>
    /// 计划链接事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void lbtnSource_Click(object sender, EventArgs e)
    {
        int i = 0;
        LinkButton bt = (LinkButton)sender;//获得当前控件
        TableCell cell = (TableCell)bt.Parent;//得到所处的父单元格
        GridViewRow iRow = (GridViewRow)cell.Parent;//得到所处父单元行         
        i = iRow.RowIndex;//得到该行的索引
        Control c = (Control)iRow.Parent;
        GridView _gdv = (GridView)c.Parent;
        int _monthPlanId = Convert.ToInt32(_gdv.DataKeys[i]["MonthPlanId"].ToString());
        if (_monthPlanId == 0)
        {
            //新增的不链接页面
        }
        else
        {
            string _url = "MonthPlanDetail.aspx?MonthPlanId=" + _monthPlanId;
            Page.RegisterStartupScript("windowsopen", "<script language=javascript>window.open('" + _url + "','newwindow','height=160,width=900,top=200,left=50,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
        }
    }

    protected void btnMofify_Click(object sender, EventArgs e)
    {
        int _count = 0;
        int _WeekId = 0;
        BLL.UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
        for (int i = 0; i < this.gdvNoEvaluateWeekPlan.Rows.Count; i++)
        {
            CheckBox ckb = (CheckBox)this.gdvNoEvaluateWeekPlan.Rows[i].Cells[0].FindControl("ckbSelect");
            if (ckb.Checked == true)
            {
                _WeekId = Convert.ToInt32(this.gdvNoEvaluateWeekPlan.DataKeys[i]["WeekPlanId"].ToString());
                _count++;
            }
        }
        //判断上部GridView是否有选中计划
        if (_count == 1)
        {
            //判断是否计划二次评估完成， 评估完成不允许修改。
            object[] _value = new object[1];
            _value[0] = _WeekId;
            DataTable userweekplan = dllUserPlanWeek.get(UserPlanWeek.field.WeekPlanId.ToString(), _value);
            if (userweekplan.Rows.Count == 0)
            {
                if (Convert.ToInt32(userweekplan.Rows[0]["PlanSendState"]) >= 4)
                {
                    Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                    return;
                }
            }

            //判断是否评估人
            Model.UserInfo objUser = new Model.UserInfo();
            object[] _user = new object[1];
            _user[0] = objUser.UserName;
            DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);

            if (_userTable.Rows.Count > 0)
            {
                object[] _username = new object[2];
                _username[0] = _userTable.Rows[0]["RealName"].ToString();
                _username[1] = _WeekId;
                DataTable _iSEvaluatePeople = dllUserPlanWeek.get(UserPlanWeek.field.EvaluatePeople.ToString(), UserPlanWeek.field.WeekPlanId.ToString(), _username);
                if (_iSEvaluatePeople.Rows.Count == 0)
                {
                    Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                }
                else
                {
                    ListItem _li = this.drpMonthDate.SelectedItem;
                    if (_li != null)
                    {
                        string _url = "UserWeekPlanModify.aspx?Id=" + _WeekId + "&MonthDate=" + _li.Value + "&url=EvaluateUserPlanWeek.aspx&QuarterDate=" + this.drpQuarterDate.SelectedValue + "&Year=" + this.drpYear.SelectedValue + "&WeekDate=" + this.drpWeekDate.SelectedValue;
                        Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                        return;
                    }
                }
            }
        }
        else
        {
            //循环下部Gridview判断计划是否选中
            for (int i = 0; i < this.gdvEvaluteCheckNote.Rows.Count; i++)
            {
                CheckBox ckb = (CheckBox)this.gdvEvaluteCheckNote.Rows[i].Cells[0].FindControl("ckbSelect");
                if (ckb.Checked == true)
                {
                    _WeekId = Convert.ToInt32(this.gdvEvaluteCheckNote.DataKeys[i]["WeekPlanId"].ToString());
                    _count++;
                }
            }
            if (_count == 1)
            {//判断是否计划二次评估完成， 评估完成不允许修改。
                object[] _value = new object[1];
                _value[0] = _WeekId;
                DataTable userweekplan = dllUserPlanWeek.get(UserPlanWeek.field.WeekPlanId.ToString(), _value);
                if (userweekplan.Rows.Count == 0)
                {
                    if (Convert.ToInt32(userweekplan.Rows[0]["PlanSendState"]) >= 4)
                    {
                        Utility.HttpHelp.alert("计划已二次评估完成，不允许修改！", Page);
                        return;
                    }
                }

                //判断是否评估人
                Model.UserInfo objUser = new Model.UserInfo();
                object[] _user = new object[1];
                _user[0] = objUser.UserName;
                DataTable _userTable = dllUserInfo.get(UserInfoManager.field.UserName.ToString(), _user);

                if (_userTable.Rows.Count > 0)
                {
                    object[] _username = new object[2];
                    _username[0] = _userTable.Rows[0]["RealName"].ToString();
                    _username[1] = _WeekId;
                    DataTable _iSEvaluatePeople = dllUserPlanWeek.get(UserPlanWeek.field.EvaluatePeople.ToString(), UserPlanWeek.field.WeekPlanId.ToString(), _username);
                    if (_iSEvaluatePeople.Rows.Count == 0)
                    {
                        Utility.HttpHelp.alert("非评估人不能修改计划", Page);
                    }
                    else
                    {
                        ListItem _li = this.drpMonthDate.SelectedItem;
                        if (_li != null)
                        {
                            string _url = "UserWeekPlanModify.aspx?Id=" + _WeekId + "&MonthDate=" + _li.Value + "&url=EvaluateUserPlanWeek.aspx&QuarterDate=" + this.drpQuarterDate.SelectedValue + "&Year=" + this.drpYear.SelectedValue + "&WeekDate=" + this.drpWeekDate.SelectedValue;
                            Page.RegisterStartupScript("windowopen", "<script>window.open('" + _url + "','','height=200,width=1000,top=300,left=20,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no');</script>");
                            return;
                        }
                    }
                }
            }
            if (_count > 1)
            {
                Utility.HttpHelp.alert("只能修改一个计划", Page);
                return;
            }
            if (_count == 0)
            {
                Utility.HttpHelp.alert("请选择一个计划", Page);
                return;
            }
        }

    }
}
